import time

from selenium import webdriver
from selenium.webdriver import Keys, ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.service import Service
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

if __name__ == '__main__':
    exe_path = "../driver/msedgedriver.exe"
    url = "https://search.jd.com/Search?keyword=%E5%A4%96%E6%98%9F%E4%BA%BA&enc=utf-8&wq=%E5%A4%96%E6%98%9F%E4%BA%BA&pvid=e169049169e04305ab1d9301690b8fc9"
    service = Service(executable_path=exe_path)
    browser = webdriver.Edge(service=service)
    browser.maximize_window()
    browser.get(url=url)

    try:
        # Constructor, takes a WebDriver instance and timeout in seconds.
        # driver WebDriver 实例
        # timeout 超时时间，单位 s
        # poll_frequency 每次调用的事件间隔，默认值 0.5s
        # ignored_exceptions 忽略的异常，默认值 NoSuchElementException
        wait = WebDriverWait(driver=browser, timeout=10, poll_frequency=0.5)
        element = wait.until(expected_conditions.presence_of_element_located((By.CLASS_NAME, "pn-next")))
        element.click()
        time.sleep(10)
    except Exception:
        print("处理异常")

